package com.fbli.Thread.Homework;

public class Homework02 {
    public static void main(String[] args) {
        WithdrawMoney withdrawMoney = new WithdrawMoney();
        new Thread(withdrawMoney).start();
        new Thread(withdrawMoney).start();
        new Thread(withdrawMoney).start();
    }
}
class WithdrawMoney implements Runnable{
    private static long money = 10000;

    @Override
    public void run() {
        withdrawMoney();
    }

    private void withdrawMoney() {
            while (true){
                synchronized (this){
                    if (money<=100){
                        System.out.println("余额不足");
                        break;
                    }
                    //取钱
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    money = money -1000;
                    System.out.println(Thread.currentThread().getName()+"取钱成功，剩余余额"+ money);
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
    }
}